import 'package:flutter/material.dart';

class HomeList extends StatelessWidget {
  const HomeList({super.key, required this.notifyList});

  final List notifyList;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        // 标题
        Row(
          children: [
            Image.asset(
              'assets/images/notice@2x.png',
              width: 20,
            ),
            const SizedBox(width: 5),
            const Text(
              '社区',
              style: TextStyle(
                color: Colors.black,
                fontWeight: FontWeight.w700,
              ),
            ),
            const Text(
              '公告',
              style: TextStyle(
                color: Colors.orange,
                fontWeight: FontWeight.w700,
              ),
            ),
          ],
        ),
        // 列表
        ListView(
          shrinkWrap: true, // 解决列表嵌套不渲染问题
          physics: const NeverScrollableScrollPhysics(), // 禁用滚动条
          children: notifyList
              .map(
                (item) => GestureDetector(
                  // 添加点击事件，跳转到详情页
                  onTap: () {
                    Navigator.pushNamed(
                      context,
                      '/detail',
                      arguments: item['id'],
                    );
                  },
                  child: Container(
                    padding: const EdgeInsets.all(10),
                    margin: const EdgeInsets.only(top: 10),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          item['title'],
                          style: const TextStyle(
                            fontWeight: FontWeight.w700,
                          ),
                        ),
                        const SizedBox(height: 5),
                        Text(item['content']),
                        const SizedBox(height: 5),
                        Text(
                          item['createdAt'],
                          style: const TextStyle(
                            color: Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              )
              .toList(),
        ),
      ],
    );
  }
}
